package com.nantaphop.hovertouchviewexample.widget;


import com.nantaphop.hovertouchviewexample.ResourceTable;

import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Image;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.element.Element;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.utils.TextAlignment;
import ohos.app.Context;

/**
 * MyThumbnailExpand class for expanded hover component
 */
public class MyThumbnailExpand extends DirectionalLayout {
    private static final int BOUNDS = 600;
    private static final int ZERO_BOUNDS = 0;
    private Element drawable;
    Context context;
    private String text;

    public MyThumbnailExpand(Context context, Element drawable, String text) {
        super(context);
        this.drawable = drawable;
        this.text = text;
        this.context = context;
        init();
    }

    public MyThumbnailExpand(Context context, AttrSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        Component rootView = LayoutScatter.getInstance(context)
                .parse(ResourceTable.Layout_view_my_thumbnail_expand, null, false);

        Image img = (Image) rootView.findComponentById(ResourceTable.Id_img);
        Text textComponent = (Text) rootView.findComponentById(ResourceTable.Id_text);
        this.drawable.setBounds(ZERO_BOUNDS, ZERO_BOUNDS, BOUNDS, BOUNDS);
        img.setImageElement(this.drawable);
        textComponent.setText(this.text);

        DirectionalLayout.LayoutConfig layoutConfig = new DirectionalLayout.LayoutConfig(
                LayoutConfig.MATCH_PARENT, LayoutConfig.MATCH_PARENT);
        layoutConfig.alignment = LayoutAlignment.CENTER;

        textComponent.setWidth(ComponentContainer.LayoutConfig.MATCH_PARENT);
        textComponent.setHeight(ComponentContainer.LayoutConfig.MATCH_CONTENT);
        textComponent.setTextAlignment(TextAlignment.CENTER);

        DirectionalLayout.LayoutConfig layoutParams = new DirectionalLayout.LayoutConfig(BOUNDS, BOUNDS);
        img.setLayoutConfig(layoutParams);

        addComponent(rootView);
        setLayoutConfig(layoutConfig);
    }

}